package com.bootdo.program.film.controller;

import java.util.List;
import java.util.Map;

import com.bootdo.program.film.domain.FilmShortDO;
import com.bootdo.program.film.service.FilmShortService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 短剧电影表
 *
 * @author guoyunfei
 * @email 2549789059@qq.com
 * @date 2023-09-02 19:31:58
 */

@Controller
@RequestMapping("/film/filmShort")
public class FilmShortController {
	@Autowired
	private FilmShortService filmShortService;

	@GetMapping()
	@RequiresPermissions("film:filmShort:filmShort")
	String FilmShort(){
	    return "film/filmShort/filmShort";
	}

	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("film:filmShort:filmShort")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<FilmShortDO> filmShortList = filmShortService.list(query);
		int total = filmShortService.count(query);
		PageUtils pageUtils = new PageUtils(filmShortList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	@RequiresPermissions("film:filmShort:add")
	String add(){
	    return "film/filmShort/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("film:filmShort:edit")
	String edit(@PathVariable("id") Long id,Model model){
		FilmShortDO filmShort = filmShortService.get(id);
		model.addAttribute("filmShort", filmShort);
	    return "film/filmShort/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("film:filmShort:add")
	public R save( FilmShortDO filmShort){
		if(filmShortService.save(filmShort)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("film:filmShort:edit")
	public R update( FilmShortDO filmShort){
		filmShortService.update(filmShort);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("film:filmShort:remove")
	public R remove( Long id){
		FilmShortDO filmShortDO = filmShortService.get(id);
		filmShortDO.setDelFlag(1);
		if(filmShortService.update(filmShortDO)>0){
			return R.ok();
		}
		return R.error();
	}

	@ResponseBody
	@RequestMapping("/approved")
	@RequiresPermissions("film:filmShort:edit")
	public R approved( FilmShortDO shortDO){

		FilmShortDO filmShortDO = filmShortService.get(shortDO.getId());
		filmShortDO.setStatus(shortDO.getStatus());
		if(filmShortService.update(filmShortDO)>0){
			return R.ok();
		}
		return R.error();
	}


}
